<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回上一个错误</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.oci-define-by-name.html">« oci_define_by_name</a></li>
      <li style="float: right;"><a href="function.oci-execute.html">oci_execute »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.oci8.html">OCI8 函数</a></li>
    <li>返回上一个错误</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.oci-error" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">oci_error</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8, PECL OCI8 &gt;= 1.1.0)</p><p class="refpurpose"><span class="refname">oci_error</span> &mdash; <span class="dc-title">返回上一个错误</span></p>

 </div>
 <div class="refsect1 unknown-unknown-seealsq" id="refsect1-function.oci-error-unknown-unknown-seealsq">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
    <span class="methodname"><strong>oci_error</strong></span>(<span class="methodparam"><span class="type">resource</span> <code class="parameter">$source</code><span class="initializer"> = ?</span></span>): <span class="type">array</span></div>

  <p class="para rdfs-comment">
   对于大多数错误，参数是最适合的资源句柄。对于
   <span class="function"><a href="function.oci-connect.html" class="function">oci_connect()</a></span>，<span class="function"><a href="function.oci-new-connect.html" class="function">oci_new_connect()</a></span>
   或 <span class="function"><a href="function.oci-pconnect.html" class="function">oci_pconnect()</a></span>
   的连接错误，不要传递参数。如果没有发现错误，<span class="function"><strong>oci_error()</strong></span>
   返回 <strong><code>false</code></strong>。<span class="function"><strong>oci_error()</strong></span>
   以一个关联数组返回错误。在此数组中，<code class="literal">code</code>
   是 oracle 错误代码而 <code class="literal">message</code> 是 oracle 的错误字符串。
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <strong>自 PHP 4.3 起</strong><br />
   <p class="para">
    <code class="literal">offset</code> 和 <code class="literal">sqltext</code>
    也包括在返回的数组中，用来指出错误发生的位置以及造成错误的原始的 SQL 文本。
   </p>
  </p></blockquote>
  <p class="para">
   <div class="example" id="example-1825">
    <p><strong>示例 #1 连接错误后显示 Oracle 错误信息</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
$conn&nbsp;=&nbsp;@oci_connect("scott",&nbsp;"tiger",&nbsp;"mydb");<br />if&nbsp;(!$conn)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error();&nbsp;&nbsp;&nbsp;//&nbsp;For&nbsp;oci_connect&nbsp;errors&nbsp;pass&nbsp;no&nbsp;handle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />}</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-1826">
    <p><strong>示例 #2 语法解析错误后显示 Oracle 错误信息</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
$stmt&nbsp;=&nbsp;@oci_parse($conn,&nbsp;"select&nbsp;'&nbsp;from&nbsp;dual");&nbsp;&nbsp;//&nbsp;note&nbsp;mismatched&nbsp;quote<br />if&nbsp;(!$stmt)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error($conn);&nbsp;&nbsp;//&nbsp;For&nbsp;oci_parse&nbsp;errors&nbsp;pass&nbsp;the&nbsp;connection&nbsp;handle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />}</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-1827">
    <p><strong>示例 #3 执行错误后显示 Oracle 错误信息和出错的语句</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
$r&nbsp;=&nbsp;oci_execute($stmt);<br />if&nbsp;(!$r)&nbsp;{<br />&nbsp;&nbsp;$e&nbsp;=&nbsp;oci_error($stmt);&nbsp;//&nbsp;For&nbsp;oci_execute&nbsp;errors&nbsp;pass&nbsp;the&nbsp;statementhandle<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['message']);<br />&nbsp;&nbsp;echo&nbsp;"&lt;pre&gt;";<br />&nbsp;&nbsp;echo&nbsp;htmlentities($e['sqltext']);<br />&nbsp;&nbsp;printf("\n%".($e['offset']+1)."s",&nbsp;"^");<br />&nbsp;&nbsp;echo&nbsp;"&lt;/pre&gt;";<br />}</span>
</code></div>
    </div>

   </div>
  </p>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    在 PHP 5.0.0 之前的版本必须使用 <span class="function"><a href="function.ocierror.html" class="function">ocierror()</a></span>
    替代本函数。该函数名仍然可用，为向下兼容作为
    <span class="function"><strong>oci_error()</strong></span> 的别名。不过其已被废弃，不推荐使用。
   </p>
  </p></blockquote>
 </div>

</div></div></div></body></html>